package com.example.yiparkapplication.activity.index.activity.myCoupons;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.yiparkapplication.R;
import com.example.yiparkapplication.entity.MonthCard;
import com.rey.material.widget.Button;

import java.util.List;
import java.util.zip.Inflater;

public class ReceiveCouponAdepter extends RecyclerView.Adapter<ReceiveCouponAdepter.ViewHolder> {
    private List<MonthCard> mMonthCardList;
    private ReceiverCouponActivity receiverCouponActivity;
    private static String mUsableStreet = null;

    public ReceiveCouponAdepter(List<MonthCard> monthCardList, ReceiverCouponActivity activity){
        mMonthCardList = monthCardList;
        receiverCouponActivity = activity;
    }

    static class ViewHolder extends RecyclerView.ViewHolder{
        View receiveCouponView;
        TextView couponName;
        TextView couponTypeUnit;
        TextView couponType;
        TextView preferentialValues;
        TextView effectiveTime;
        Button receiveButton;
        TextView usableTimes;
        LinearLayout couponInfo;
        TextView usableStreet;
        ImageView image;
        public ViewHolder(View view){
            super(view);
            receiveCouponView = view;
            couponName = view.findViewById(R.id.id_coupon_name);
            couponTypeUnit = view.findViewById(R.id.id_coupon_type_unit);
            couponType = view.findViewById(R.id.id_coupon_type);
            preferentialValues = view.findViewById(R.id.id_preferential_values);effectiveTime = view.findViewById(R.id.id_effective_time);
            receiveButton = view.findViewById(R.id.id_receive);
            usableTimes = view.findViewById(R.id.id_usable_times);
            couponInfo = view.findViewById(R.id.id_coupon_usable_info);
            usableStreet = view.findViewById(R.id.id_usable_street);
            image = view.findViewById(R.id.id_up_or_down_image);
        }
    }

    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int ViewType){
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.fragment_receive_coupons_list_layout, parent, false);
        final ReceiveCouponAdepter.ViewHolder holder = new ReceiveCouponAdepter.ViewHolder(view);
        holder.receiveCouponView.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                int position = holder.getAdapterPosition();
                String monthCardId = mMonthCardList.get(position).getMonthCardId().toString();
                receiverCouponActivity.appointmentCoupon(monthCardId);
            }
        });
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull final ReceiveCouponAdepter.ViewHolder holder, int position){
        final MonthCard monthCard = mMonthCardList.get(position);
        holder.couponName.setText(monthCard.getMonthCardName());

    }

    @Override
    public int getItemCount(){
        return mMonthCardList.size();
    }

    public static void getUsableStreetofReceiveCouponActivity(String streetName){
        mUsableStreet = streetName;
    }

}
